<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: aqua;
            position: absolute;
        }
        
        span {
            position: absolute;
        }
    </style>

</head>

<body>

    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <span>sad</span>
</body>
<script src="js/jquery.min.js"></script>
<script>
    $.fn.extend({
        drag: function() {
            $(this).mousedown(function(ev) {
                var top = ev.pageY - $(this).offset().top;
                var left = ev.pageX - $(this).offset().left;

                var _this = this;
                $(document).mousemove(function(ev) {
                    $(_this).css({
                        top: ev.pageY - top,
                        left: ev.pageX - left
                    });
                })

                $(document).mouseup(function(ev) {
                    $(document).off("mousemove")

                })

            })
            return this;
        }

    })

    $("div,span").drag().mouseup(function() {
        $(this).css('backgroundColor', 'red')
    });
</script>

</html>